// pages/train/train.js
import request from '../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    pageSize:1,
    pageNum:4,
    isPull:true,
    traindata:[],
    iShidden:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var page = that.data.pageSize
    that.getTrain(page)
    this.getBanner()
    },
   // 培训服务
  getTrain:function(page){
    var that = this
      var data = {
        page:page,
        limit:that.data.pageNum
      }
    request.get('article/list/6',data,{ noAuth : true}).then(res=>{
      if(res.data.length >0){
        that.setData({
          traindata:that.data.traindata.concat(res.data)
        })
      }else{
        that.setData({
          isPull:false
        })
      }
      })
  },
  Godetail:function(e){
   var url = e.currentTarget.dataset.url
   wx.navigateTo({
     url: url,
   })
  },
  getBanner:function(){
    request.get('banner/training_services',{},{ noAuth : true}).then(res=>{
      console.log(res)
      this.setData({
        banner:res.data
      })
    })
  },
  needsSubmit:function(){
    var that = this
    wx.getSetting({
      success(res){
       if(res.authSetting['scope.userInfo']){
        wx.navigateTo({
          url: './needsSubmit/needsSubmit',
        })
       }else{
        wx.showModal({
          content: '请前往【个人中心】登录授权',
          success(res){
            if(res.confirm){
              setTimeout(() => {
                  wx.switchTab({
                       url: '../user/user',
                     })
              }, 500);
            }
          }
        })
       }
      }
    })
    

  },
  details:function(o){
    var id = o.currentTarget.dataset.id
    console.log(o)
    wx.navigateTo({
      url: './case/case?id='+id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
   var value = this.data
   if(value.isPull){
    var nextpage = ++value.pageSize
    this.getTrain(nextpage)
   }
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})